{% comment %}
/* Copyright 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
{% endcomment %}
{% extends 'base.html' %}
{% block content %}
{% if action %}
  <div id="edit-message">
    {% if confirmation or warnings.gia %}
      {% if confirmation %}
        <div class="success">Update Completed!</div>
      {% else %}
        <div class="warning">Only the author can edit the post.</div>
      {% endif %}
    {% else %}
      &nbsp;
    {% endif %}
  </div>
  <form method="POST">
    <input type="hidden" name="post" value="{{post.key}}">
    <input type="hidden" name="author" value="{{user.key}}">
    <table class="table-list">
      <tr>
        <td class="table-input-label">
          Title*:
          {% if warnings.title %}<br>
          <span class="warning">Title is required.</span>
          {% endif %}</td>
        <td class="table-input">
          <input
            class="text-input"
            type="text"
            name="title"
            value="{{post.title|default_if_none:""|escape}}">
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Path:
          {% if warnings.path %}<br>
          <span class="warning">
            The path must be unique and not contain spaces.
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <input
            type="text"
            name="path"
            class="text-input"
            value="{{post.path|addslashes}}">
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Canonical:
          {% if warnings.canonical %}
          <span class="warning"><br>
            Please double check your canonical url.</span>
          {% endif %}
        </td>
        <td class="table-input">
          <input
            type="text"
            name="canonical"
            class="text-input"
            value="{{post.canonical|default_if_none:""|escape}}">
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Keywords:
          {% if warnings.keywords %}<br>
          <span class="warning">It appears there was a problem with your
            keywords.</span>
          {% endif %}
        </td>
        <td class="table-input">
          <textarea class="textarea-small" name="keywords"
            >{{post.keywords|default_if_none:""|escape}}</textarea>
            (comma, separated, keywords)
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Description:
          {% if warnings.description %}<br>
          <span class="warning">It appears there was an issue with your
            description.</span>
          {% endif %}
        </td>
        <td class="table-input">
          <textarea class="textarea-med" name="description"
            >{{post.description|default_if_none:""|escape}}</textarea>
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Body*:
          {% if warnings.body %}<br>
          <span class="warning">Body is required.</span>
          {% endif %}
        </td>
        <td class="table-input">
          <textarea class="textarea-large" name="body"
            >{{post.body|default_if_none:""|escape}}</textarea>
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          NoIndex:
          {% if warnings.noindex %}<br>
          <span class="warning">This checkbox was not checked or unchecked
            properly.</span>
          {% endif %}
        </td>
        <td class="table-input">
          <input type="checkbox" name="noindex" value="true"
          {% if post.noindex %} checked="true" {% endif %}>
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          NoFollow:
          {% if warnings.nofollow %}<br>
          <span class="warning">You might want to double check how you
            checked that checkbox.</span>
          {% endif %}
        </td>
        <td class="table-input">
          <input type="checkbox" name="nofollow" value="true"
          {% if post.nofollow %} checked="true" {% endif %}>
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          NoArchive:
          {% if warnings.noarchive %}<br>
            <span class="warning">How do you mess up checking a box?</span>
          {% endif %}
        </td>
        <td class="table-input">
          <input type="checkbox" name="noarchive" value="true"
            {% if post.noarchive %} checked="true" {% endif %}>
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          NoSnippet:
          {% if warnings.nosnippet %}<br>
            <span class="warning">How do you mess up checking a box?</span>
          {% endif %}
        </td>
        <td class="table-input">
          <input type="checkbox" name="nosnippet" value="true"
            {% if post.nosnippet %} checked="true" {% endif %}>
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          NoODP:
          {% if warnings.noodp %}<br>
          <span class="warning">Your managed to mess up checking an unrequired
            checkbox. How'd you do that?</span>
          {% endif %}
        </td>
        <td>
          <input
            type="checkbox"
            class="warning"
            name="noodp"
            {% if post.noodp %}
            checked="true"
            {% endif %}
            value="true">
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          <b>Published:</b>
        </td>
        <td class="table-input">
          <input type="checkbox" name="is_published" value="true"
            {% if post.is_published %} checked="true" {% endif %}>
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          <input type="submit" name="save" value="Save">
        </td>
        <td class="table-input">
          <span class="required">* Required</span>
          <input type="submit" name="done" value="Done">
          <input type="submit" name="cancel" value="Cancel">
        </td>
      </tr>
    </table>
  </form>
{% else %}
  <div id="new-post">
    <a href="/admin/post?action=new" id="new-post-link">+ New Post</a>
  </div>
  <table class="table-list">
    <thead>
      <tr class="table-head">
        <td>Action</td>
        <td>Title</td>
        <td>Author</td>
        <td>Created</td>
        <td>Edited</td>
        <td>Published</td>
      </tr>
    </thead>
    <tbody>
    {% for post in posts %}
    {% ifequal post.author.gia user.gia %}
      <tr>
        <td>
        <a href='/admin/post?action=edit&post={{post.key}}'>Edit</a> |
        <a href='/admin/post?action=delete&post={{post.key}}'>Delete</a>
        </td>
        <td>
        <a
        href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}">
            {{post.title|truncatewords:8}}
        </a>
        </td>
        <td>
          {{post.author.nickname}}
        </td>
        <td>
          {{post.creation_date|date:"n/j - g:i"}}
        <td>
          {{post.edit_date|date:"n/j - g:i"}}
        </td>
        <td>
          {% if post.is_published %}
            {{post.publish_date|date:"n/j - g:i"}}
          {%else %}
            <span style="color:red">False</span>
          {% endif %}
        </td>
      </tr>
      {% endifequal %}
      {% endfor %}
    </tbody>
  </table>
{% endif %}
{% endblock %}
